package com.itheima.web;

import com.itheima.pojo.MyUser;
import com.itheima.service.MyUserService;
import com.itheima.support.PageResult;
import com.itheima.support.QueryPageBean;
import com.itheima.support.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * @author admin
 */

@RestController
@RequestMapping("/user")
public class MyUserController {
    @DubboReference
    private MyUserService myUserService;

    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody MyUser user) {
        return Result.build(myUserService.add(user));
    }

    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody MyUser user) {
        return Result.build(myUserService.update(user));
    }

    @GetMapping("/deleteById/{id}")
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        return Result.build(myUserService.delete(id));
    }

    @PostMapping("/findByPage")
    public PageResult findByPage(@RequestBody QueryPageBean queryPageBean) {
        return myUserService.findByPage(queryPageBean);
    }

    @PostMapping("/updatePWByName")
    public Result<Boolean> updatePasswordByName(@RequestBody MyUser user) {
        return Result.build(myUserService.updatePasswordByName(user));
    }

    @GetMapping("/findAll")
    public Result<java.util.List<MyUser>> findAll(){
        return Result.build(myUserService.list());
    }
}
